Data type conversion
When you are creating your application, there will be situations when you have to adapt the supported data types for the use in expressions or assignments. Neuron Power Engineer provides the following type conversions for this adaption:
Explicit conversion of data type
Enter the call of one of the convert functions when creating your application in order to convert a data type into the required data type. Observe the conversion rules.
Possible results of an explicit conversion
|
Implicit conversion of data type
Due to the implicit conversion of Neuron Power Engineer you do not have to enter additional code in your application, if you want to convert the following data types:
Note on how to interpret the figure: The arrows present the possible conversions paths. Therefore: A data type can be converted to the data type to which the arrow points. If this data type can be converted to data types again, the data type in front can be converted to the following data types as well.
-
Example 1:
BOOL
can be converted toBYTE
. AsBYTE
can be converted toWORD
,BOOL
can be converted toWORD
as well. AsWORD
can be converted toDWORD
,BYTE
andBOOL
can be converted toDWORD
as well. And so on, along the direction of arrow. -
Example 2:
SINT
can be converted toINT
. AsINT
can be converted toDINT
andREAL
,SINT
can be converted toDINT
andREAL
. And so on, along the direction of arrow.
Results of an implicit conversion: Value and accuracy of the original data type is kept. However, observe the conversion rules.
Implicit conversion of safe data type
See under "Safe data types".
Conversion rules
-
When converting a
REAL
/LREAL
value into anANY_INT
value, it is rounded up or down to the next even →integer. As a consequence, half portions (such as0.5
) are rounded to the next even integer. Example: TheREAL
value1.5
and theREAL
value2.5
are both converted toANY_INT
value2
because this value is the next even integer.ANY_INT
is...USINT
,UINT
,UDINT
,ULINT
,SINT
,INT
,DINT
orLINT
(corresponds to →generic data typeANY_INT
) -
When explicitly converting an
ANY_SIGNED
value (a signed value) into anANY_UNSIGNED
value (an unsigned value) and vice versa, the bit pattern of the value is interpreted in the specific data format.ANY_SIGNED
resp.ANY_UNSIGNED
is...SINT
,INT
,DINT
orLINT
(corresponds to →generic data typeANY_SIGNED
)USINT
,UINT
,UDINT
orULINT
(corresponds to →generic data typeANY_UNSIGNED
)Hence:
Original value
Result (converted value)
-1
(as signed value)FFhex
orFFFFhex
orFFFFFFFFhex
(as unsigned value, depending on the data type)128
(=80hex
) asUSINT
-128
(=80hex
) asSINT
129
(=81hex
) asUSINT
-127
(=81hex
) asSINT
255
(=FFhex
) asUSINT
-1
(=FFhex
) asSINT
-
If converting data types to the
TIME
data type and vice versa, the conversion is always based on seconds.